//
//  PPImageCutController.m
//  图片的裁剪
//
//  Created by xuzhongping on 2016/11/11.
//  Copyright © 2016年 xuzhongping. All rights reserved.
//

#import "PPImageCutController.h"
#import <SDAutoLayout/UIView+SDAutoLayout.h>
#import "PPImageToolBar.h"
@interface PPImageCutController ()

/** 工具栏 */
@property (nonatomic,weak)UIView *toolBar;

/** 内容 */
@property (nonatomic,weak)UIView *contentView;

/** 图片裁剪区 */
@property (nonatomic,weak)UIImageView *cutImageView;

@end

@implementation PPImageCutController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initUI];
    [self checkoutImage];
}

- (void)initUI{
    self.view.backgroundColor = [UIColor whiteColor];
    PPImageToolBar *toolBar = [[PPImageToolBar alloc]init];
    [self.view addSubview:toolBar];
    self.toolBar = toolBar;
    
    toolBar.sd_layout.leftEqualToView(self.view).rightEqualToView(self.view).bottomEqualToView(self.view).heightIs(88);
    
    UIView *contentView = [[UIView alloc]init];
    contentView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:contentView];
    self.contentView = contentView;
    
    contentView.sd_layout.leftEqualToView(self.view).rightEqualToView(self.view).topEqualToView(self.view).bottomSpaceToView(toolBar,0);
    
    UIImageView *cutImageView = [[UIImageView alloc]init];
    cutImageView.image = _cutImage;
    [contentView addSubview:cutImageView];
    self.cutImageView = cutImageView;
}

- (void)checkoutImage{
    CGSize imageSize = _cutImage.size;
    CGFloat ratio = imageSize.width / imageSize.height;
     [_cutImageView sd_clearAutoLayoutSettings];
//    if (imageSize.width >= imageSize.height) {
//        _cutImageView.sd_layout.leftEqualToView(_contentView).rightEqualToView(_contentView).centerYEqualToView(_contentView);
//    }else {
//        _cutImageView.sd_layout.topEqualToView(_contentView).bottomEqualToView(_contentView).centerXEqualToView(_contentView);
//    }
    _cutImageView.sd_layout.topEqualToView(_contentView).bottomEqualToView(_contentView).leftEqualToView(_contentView).rightEqualToView(_contentView);
    [self.view updateLayout];
}

@end
